package jk.spider.core.event.URLFound.impl;

import java.util.Set;

import jk.spider.core.SpiderController;
import jk.spider.core.event.CoreEvent;
import jk.spider.core.event.URLFound.URLFound;
import jk.spider.core.event.impl.URLFoundEvent;
import jk.spider.model.Resource;

import org.apache.log4j.Logger;

public class DetailURLFound extends URLFound {
	private static final Logger log = Logger.getLogger(DetailURLFound.class);
	
	public static final String URL_PLUGIN_NAME = "DETAIL URL FOUND";
    public static final String URL_PLUGIN_VERSION = "v1.0";
    public static final String URL_PLUGIN_DESCRIPTION = "";
    
    public int fCount = 0;
    
    public DetailURLFound(String reg) {
		super(reg);
	}
    
    public DetailURLFound(String reg, Set<String> filterSet) {
		super(reg, filterSet);
	}
    
	public boolean findUrl(URLFoundEvent event) {
		SpiderController controller = event.getController();
		Resource eventRes = event.getResource(); 
		String dUrl = event.getSrc();
//		if(dUrl.indexOf("dispbbs.asp?boardID=") != -1)
//			System.out.println(dUrl);
		if(dUrl.endsWith("%7D}") || dUrl.endsWith("%7D") || dUrl.endsWith("}"))
			return false;
		if(!this.isUrlValid(dUrl)) 
			return false;
		super.findDetail(dUrl, eventRes, controller);
		return true;
	}
	
	public void initialize() {
		log.info(URL_PLUGIN_NAME);
		log.info(URL_PLUGIN_VERSION);
		log.info(URL_PLUGIN_DESCRIPTION);
	}
	
	@Override
	public String getUrlFoundType() {
		return CoreEvent.COREEVENT_DETAIL;
	}

}
